import Vue from "vue";
import VueRouter from "vue-router";
import MainItem from "@/views/project/MainItem.vue";
import SubItem from "@/views/project/SubItem.vue";
import ProjectSide from "@/views/personnel/ProjectSide.vue";
import EpidemicRisk from "@/views/epidemicRisk/EpidemicRisk.vue";
import AttendanceInformation from "@/views/attendanceInformation/AttendanceInformation.vue";
import Login from "../views/login/Login.vue";
import EpidemicMsg from "../views/epidemicRisk/EpidemicMsg.vue";
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "epidemicRisk",
    component: EpidemicRisk
  },
  {
    path: "/mainItem",
    name: "mainItem",
    component: MainItem
  },
  {
    path: "/subItem",
    name: "subItem",
    component: SubItem
  },
  {
    path: "/projectSide",
    name: "projectSide",
    component: ProjectSide
  },
  {
    path: "/epidemicRisk",
    name: "epidemicRisk",
    component: EpidemicRisk
  },
  {
    path: "/attendanceInformation",
    name: "attendanceInformation",
    component: AttendanceInformation
  },
  {
    path: "/login",
    name: "login",
    component: Login
  },
  {
    path: "/epidemicmsg",
    name: "epidemicmsg",
    component: EpidemicMsg
  }
];

const router = new VueRouter({
  routes
});
router.beforeEach((to, from, next) => {
  if (!window.sessionStorage.getItem("token") && to.path !== "/login") {
    next("/login");
  } else {
    next();
    // const startTime = window.sessionStorage.getItem("starttime");
    // if (Date.now() - startTime > 97200000) {
    //   window.sessionStorage.removeItem("id");
    //   window.sessionStorage.removeItem("token");
    //   window.sessionStorage.removeItem("name");
      if (!window.sessionStorage.getItem("token")) {
        next("/login");
      }
    // }
  }
});

export default router;
